#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        int n = matrix.size();
        int h = n / 2;
        int w = h;
        if (n % 2 == 1) {
            w += 1;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int temp1 = matrix[j][n - 1 - i];
                matrix[j][n - 1 - i] = matrix[i][j];
                int temp2 = matrix[n - 1 - i][n - 1 - j];
                matrix[n - 1 - i][n - 1 - j] = temp1;
                temp1 = matrix[n - 1 - j][i];
                matrix[n - 1 - j][i] = temp2;
                matrix[i][j] = temp1;
            }
        }
    }
};